﻿using System;
using System.Data;
using System.Collections.Generic;
using kim.Common;
using kim.Model;
namespace kim.BLL
{
	/// <summary>
	/// link
	/// </summary>
	public partial class link
	{
		private readonly kim.DAL.link dal=new kim.DAL.link();
		public link()
		{}
		#region  Method
        /// <summary>
        /// 分页控制
        /// </summary>
        /// <param name="tbname">要分页显示的表名</param>
        /// <param name="FieldKey">用于定位记录的主键(惟一键)字段,可以是逗号分隔的多个字段</param>
        /// <param name="PageCurrent">要显示的页码</param>
        /// <param name="PageSize">每页的大小(记录数)</param>
        /// <param name="FieldShow">以逗号分隔的要显示的字段列表,如果不指定,则显示所有字段</param>
        /// <param name="FieldOrder">以逗号分隔的排序字段列表,可以指定在字段后面指定DESC/ASC,用于指定排序顺序</param>
        /// <param name="Where">查询条件</param>
        /// <returns></returns>
        public DataSet GetNewsPager(int PageCurrent, int PageSize, string FieldShow, string FieldOrder, string Where)
        {
            return dal.GetNewsPager("link", "id", PageCurrent, PageSize, FieldShow, FieldOrder, Where);
        }
		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(kim.Model.link model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(kim.Model.link model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public kim.Model.link GetModel(int id)
		{
			
			return dal.GetModel(id);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public kim.Model.link GetModelByCache(int id)
		{
			
			string CacheKey = "linkModel-" + id;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (kim.Model.link)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<kim.Model.link> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<kim.Model.link> DataTableToList(DataTable dt)
		{
			List<kim.Model.link> modelList = new List<kim.Model.link>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				kim.Model.link model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new kim.Model.link();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["title"]!=null && dt.Rows[n]["title"].ToString()!="")
					{
					model.title=dt.Rows[n]["title"].ToString();
					}
					if(dt.Rows[n]["site_url"]!=null && dt.Rows[n]["site_url"].ToString()!="")
					{
					model.site_url=dt.Rows[n]["site_url"].ToString();
					}
					if(dt.Rows[n]["img_url"]!=null && dt.Rows[n]["img_url"].ToString()!="")
					{
					model.img_url=dt.Rows[n]["img_url"].ToString();
					}
					if(dt.Rows[n]["is_image"]!=null && dt.Rows[n]["is_image"].ToString()!="")
					{
						model.is_image=int.Parse(dt.Rows[n]["is_image"].ToString());
					}
					if(dt.Rows[n]["sort_id"]!=null && dt.Rows[n]["sort_id"].ToString()!="")
					{
						model.sort_id=int.Parse(dt.Rows[n]["sort_id"].ToString());
					}
					if(dt.Rows[n]["is_red"]!=null && dt.Rows[n]["is_red"].ToString()!="")
					{
						model.is_red=int.Parse(dt.Rows[n]["is_red"].ToString());
					}
					if(dt.Rows[n]["is_lock"]!=null && dt.Rows[n]["is_lock"].ToString()!="")
					{
						model.is_lock=int.Parse(dt.Rows[n]["is_lock"].ToString());
					}
					if(dt.Rows[n]["add_time"]!=null && dt.Rows[n]["add_time"].ToString()!="")
					{
						model.add_time=DateTime.Parse(dt.Rows[n]["add_time"].ToString());
					}
					if(dt.Rows[n]["typeid"]!=null && dt.Rows[n]["typeid"].ToString()!="")
					{
						model.typeid=int.Parse(dt.Rows[n]["typeid"].ToString());
					}
					if(dt.Rows[n]["ChannelID"]!=null && dt.Rows[n]["ChannelID"].ToString()!="")
					{
						model.ChannelID=int.Parse(dt.Rows[n]["ChannelID"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

